package com.example.lancooznbk.view.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.andview.refreshview.XRefreshView;

/**
 * Created by Administrator on 2018/4/8.
 */

public class DecoratorXRefreshView extends XRefreshView {
    public float mDownX;
    public float mDownY;
    // 记录viewPager是否拖拽的标记
    private boolean mIsVpDragger;
    private boolean first = true;
    private boolean drop_down = false;
    private boolean on_pull = false;

    public DecoratorXRefreshView(Context context) {
        super(context);
    }
    public DecoratorXRefreshView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        /*Log.e("DXRE","dispatchTouchEvent");
        int action  =ev.getAction();
        Log.e("DXRE","dispatchTouchEvent1"+super.dispatchTouchEvent(ev));
        switch (action){
            case MotionEvent.ACTION_DOWN:
                mDownX = ev.getX();
                mDownY = ev.getY();
                    // 初始化标记
                mIsVpDragger = false;
                break;
            case MotionEvent.ACTION_MOVE:
                // 如果viewpager正在拖拽中，那么不拦截它的事件，直接return false；
                float dy = Math.abs((ev.getY() - mDownY));
                float dx = Math.abs((ev.getX() - mDownX));
                if ((Math.abs(dy) < Math.abs(dx) && first == true) || drop_down ==true) {
                    //每次拦截的down都把触摸状态设置成了TOUCH_STATE_NONE 只有返回true才会走onTouchEvent 所以写在这里就够了
                    first = false;
                    drop_down = true;
                    Log.e("DXRE","ACTION_MOVE1"+super.dispatchTouchEvent(ev));
                    return false;
                } else if((Math.abs(dy) > Math.abs(dx) && first == true) || on_pull ==true){
                    on_pull = true;
                    first = false;
                    Log.e("DXRE","ACTION_MOVE2"+super.dispatchTouchEvent(ev));
                    return true;
                }
            case MotionEvent.ACTION_UP:
                return super.dispatchTouchEvent(ev);
            case MotionEvent.ACTION_CANCEL:
                // 初始化标记
                first = true;
                drop_down = false;
                on_pull = false;
                break;
        }*/
        return super.dispatchTouchEvent(ev);
    }
//    @Override
//    public boolean onInterceptTouchEvent(MotionEvent ev) {
//
//        return super.onInterceptTouchEvent(ev);
//    }


}
